package com.example.lambda;

import java.util.Objects;
import java.util.function.Function;

/**
 *
 *
 * @author qingyan 2022-03-09
 */
@FunctionalInterface
public interface CheckedFunction<T, R> {

    R apply(T t) throws Throwable;
    // 优化
    default <T, R> Function<T, R> apply(CheckedFunction<T, R> function) {
        Objects.requireNonNull(function);//如果为空会抛nullpoint异常
        return t -> {
            try {
                return function.apply(t);
            } catch (Throwable ex) {
                throw new RuntimeException(ex);
            }
        };
    }

}
